export const timeConvert = (timestamp:any) => {
    timestamp = timestamp+'';
    timestamp = timestamp.length==10?timestamp*1000:timestamp;
    var date = new Date(timestamp);
    var y = date.getFullYear();  
    var m = (date.getMonth() + 1).toString();  
    m = parseInt(m) < 10 ? ('0' + m) : m;  
    var d = date.getDate().toString();  
    d = parseInt(d) < 10 ? ('0' + d) : d;  
    var h = date.getHours().toString();
    h = parseInt(h) < 10 ? ('0' + h) : h;
    var minute = date.getMinutes().toString();
    var second = date.getSeconds().toString();
    minute = parseInt(minute) < 10 ? ('0' + minute) : minute;  
    second = parseInt(second) < 10 ? ('0' + second) : second; 
    return y + '-' + m + '-' + d +' '+ h +':'+ minute +':' + second;
  }
  export const setFormat = (x:any) =>{
    if (x < 10) {
      x = "0" + x;
    }
    return x;
  }
  export const beforeNowtimeBySec = (beforetime:any) => {
    var date = new Date(); //日期对象
    date.setSeconds (date.getSeconds () - beforetime);
    var now = "";
    now = date.getFullYear()+"-"; //读英文就行了
    now = now + (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';//取月的时候取的是当前月-1如果想取当前月+1就可以了
    now = now + setFormat(date.getDate())+" ";
    now = now + setFormat(date.getHours())+":";
    now = now + setFormat(date.getMinutes())+":";
    now = now + setFormat(date.getSeconds())+"";
    return now;
}